#include <bits/stdc++.h>
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define _int long long
using namespace std;
struct car{
    _int d,v,a,f=-1,t=-1;
    void setall(_int nd,_int nv,_int na){
        d=nd;
        v=nv;
        a=na;
    }
    bool found_by_one(_int p,_int V){
        if (d>p)return false;
        return ((v*v+2*a*(p-d))>V*V);
    }
    bool found(vector<_int> p,_int V){
        if (v<V && a<=0)return false;
        if (p[p.size()-1]<d)return false;
        if (a>0 && V*V>(p[p.size()-1]-d)*2*a+v*v)return false;
        for (_int i=0;i<p.size();i++){
            if (found_by_one(p[i],V)){
                if (f==-1)f=p[i];
                t=max(t,p[i]);
            }
        }

        return f>=0;
    }
};
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    _int t;
    cin>>t;
    while(t--){
        _int n,m,l,v;
        cin>>n>>m>>l>>v;
        vector<car> cars(n);
        vector<_int> ce(m);
        for (_int i=0;i<n;i++){
            _int d,v,a;
            cin>>d>>v>>a;
            cars[i].setall(d,v,a);
        }
        for (_int i=0;i<m;i++){cin>>ce[i];}
        vector<_int> cnt(ce[m-1]+1);
        vector<vector<car>> cntvcars(ce[m-1]+1,vector<car>(0));

        _int res1=0,res2=0;
        for (auto &car:cars){
            if(car.found(ce,v)){
                res1+=1;
                cnt[car.f]++;
                cntvcars[car.f].push_back(car);
            }
        }
        vector<car> vcars(res1);
        _int ind=0;
        for(_int i=0;i<=ce[m-1];i++){
            for(_int j=0;j<cnt[i];j++){
                vcars[ind++]=cntvcars[i][j];
            }
        }
        _int z=0;
        while(z<vcars.size()){
            _int t=vcars[z].t;
            z++;
            res2++;
            while(z<vcars.size() && vcars[z].f<=t){
                t=min(vcars[z].t,t);
                z++;
            }
        }
        res2=m-res2;

        cout<<res1<<" "<<res2<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
